package com.jeesite.modules.dp.web.usercart;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.dp.entity.usercart.DpUsercart;
import com.jeesite.modules.dp.service.usercart.DpUsercartService;

/**
 * 购物车Controller
 * @author hancing
 * @version 2024-12-20
 */
@Controller
@RequestMapping(value = "${adminPath}/dp/usercart/dpUsercart")
public class DpUsercartController extends BaseController {

	@Autowired
	private DpUsercartService dpUsercartService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DpUsercart get(String id, boolean isNewRecord) {
		return dpUsercartService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("dp:usercart:dpUsercart:view")
	@RequestMapping(value = {"list", ""})
	public String list(DpUsercart dpUsercart, Model model) {
		model.addAttribute("dpUsercart", dpUsercart);
		return "modules/dp/usercart/dpUsercartList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("dp:usercart:dpUsercart:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DpUsercart> listData(DpUsercart dpUsercart, HttpServletRequest request, HttpServletResponse response) {
		dpUsercart.setPage(new Page<>(request, response));
		Page<DpUsercart> page = dpUsercartService.findPage(dpUsercart);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("dp:usercart:dpUsercart:view")
	@RequestMapping(value = "form")
	public String form(DpUsercart dpUsercart, Model model) {
		model.addAttribute("dpUsercart", dpUsercart);
		return "modules/dp/usercart/dpUsercartForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("dp:usercart:dpUsercart:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DpUsercart dpUsercart) {
		dpUsercartService.save(dpUsercart);
		return renderResult(Global.TRUE, text("保存购物车成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("dp:usercart:dpUsercart:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DpUsercart dpUsercart) {
		dpUsercartService.delete(dpUsercart);
		return renderResult(Global.TRUE, text("删除购物车成功！"));
	}
	
}